<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车</title>

<script type="text/javascript">
function clearcart(){
  var b=window.confirm("您确定要清空购物车吗");
  if(b){
	 window.location.href="${pageContext.request.contextPath }/UpdateCartServlet"; 
  }
}
  
  function update(input,id,old){
	  var quality =input.value;
	var q=window.confirm("你确认改为："+quality+"吗");
	if(q){
window.location.href="${pageContext.request.contextPath }/UpdateCartServlet?bookid="+id+"&quality="+quality;
  }else{
	  input.value=old;
  }
  }
</script>
</head>
<body>
	<br>
	<h2>购物车列表</h2>
	<br>
	<c:if test="${ !empty(cart.map) }">
		<table border="1" width="80%">
			<tr>

				<td>书名</td>
				<td>作者</td>
				<td>单价</td>
				<td>数量</td>
				<td>小计</td>
				<td>操作</td>

			</tr>

			<c:forEach var="me" items="${cart.map }">
				<tr>
					<td>${me.value.book.name }</td>
					<td>${me.value.book.author }</td>
					<td>${me.value.book.price }</td>
					<td><input style="width: 30px;" type="text" name="quality"
						value="${me.value.quality }"
						onchange="update(this,${me.value.book.id },${me.value.quality })"></td>
					<td>${me.value.price }</td>
					<td><a
						href="${pageContext.request.contextPath }/DeleteServlet?bookid=${me.value.book.id}">删除</a>
					</td>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="2"><a href="javascript:clearcart()">清空购物车</a></td>
				<td colspan="2">合计</td>
				<td colspan="2">${cart.price }</td>
			</tr>
		</table>
	</c:if>
	<c:if test="${empty(cart.map) }">
	您还没有购买书
	
	</c:if>
</body>
</html>